#include "imgui/StringEditor.h"

bool ImGui::StringEditor::InputMultiString(const std::string &label, std::string &value, int row)
{

    ImVector<char> my_str;
    for (auto ch : value)
    {
        my_str.push_back(ch);
    }

    my_str.push_back(0);

    bool res = InputMultiString(label, my_str, row);

    value.clear();
    for (auto r : my_str)
    {
        value.push_back(r);
    }
    value = value.substr(0, value.length() - 1);

    return res;
}

bool ImGui::StringEditor::InputMultiString(const std::string label, ImVector<char> &my_str, int row)
{

    if (my_str.empty())
    {
        my_str.push_back(0);
    }
    bool res = ImGui::InputTextMultiline(label.c_str(), my_str.begin(), (size_t)my_str.size(), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * row),
                                         ImGuiInputTextFlags_CallbackResize, Funcs::MyResizeCallback, (void *)&my_str);

    return res;
}

bool ImGui::StringEditor::InputString(const std::string label, std::string &value)
{
    ImVector<char> my_str;

    for (char ch : value)
    {
        my_str.push_back(ch);
    }

    my_str.push_back(0);

    bool res = ImGui::InputText(label.c_str(), my_str.begin(), (size_t)my_str.size(),
                                ImGuiInputTextFlags_CallbackResize, Funcs::MyResizeCallback, (void *)&my_str);

    value.clear();
    for (const char &rch : my_str)
    {
        value.push_back(rch);
    }
    value = value.substr(0, value.length() - 1);
    return res;
};